# user：hp
# web自动化阶段 2022/6/2
# 时间 22:42
"""json schema辅助断言"""
import jsonschema


def assert_unify(resp, expect):
    assert resp.status_code == 200
    # 先取出data
    # expect.popitem()
    # 以列表方式获取key
    keys_list = list(expect.keys())
    # print(keys_list)
    schema = {
        "type": "object",
        "required": [*keys_list],
        "properties": {
            keys_list[0]: {"const": expect[keys_list[0]]},
            keys_list[1]: {"const": expect[keys_list[1]]},
            keys_list[2]: {"pattern": "^{}".format(expect[keys_list[2]])},
            keys_list[3]: {"type": '{}'.format(expect[keys_list[3]])}
        }
    }
    jsonschema.validate(resp.json(), schema)
